package com.fansl.allround.common.security.jwt;

import com.fansl.allround.common.core.constant.SecurityConstants;
import com.fansl.allround.common.security.service.AllroundSysUser;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fansl
 * @Description: TODO
 * @date 2019/9/25 10:58
 */
@Component
public class AllroundSysUserJwtTokenEnhancerHandler implements JwtTokenEnhancerHandler {
    /**
     * 获取token的Info
     *
     * @return
     */
    @Override
    public Map<String, Object> getInfoToToken(OAuth2Authentication authentication) {
        final Map<String, Object> additionalInfo = new HashMap<>(4);
        AllroundSysUser allroundSysUser = (AllroundSysUser) authentication.getUserAuthentication().getPrincipal();
        additionalInfo.put(SecurityConstants.DETAILS_LICENSE, SecurityConstants.PROJECT_LICENSE);
        additionalInfo.put(SecurityConstants.DETAILS_USER_ID, allroundSysUser.getId());
        additionalInfo.put(SecurityConstants.DETAILS_USERNAME, allroundSysUser.getUsername());
        additionalInfo.put(SecurityConstants.DETAILS_DEPT_ID, allroundSysUser.getDeptId());
        return additionalInfo;
    }
}
